import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import '../../../config/theme_color.dart';
import '../../common/route_page/route_name.dart';
import '../../common/utils/screen_size_utils.dart';
import '../../config/web_page.dart';
import '../../generated/l10n.dart';

class AgreePrivacyLoginView extends StatelessWidget {
  final Function? agreeAction;

  const AgreePrivacyLoginView({this.agreeAction, super.key});

  @override
  Widget build(BuildContext context) {
    return getPrivacyView(context);
  }

  Widget getPrivacyView(BuildContext context) {
    double height = ScreenSizeUtils.deviceScreenWidth(context) - 40 * 2;
    return Center(
      child: Container(
        height: height,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10),
          color: Colors.white,
        ),
        margin: const EdgeInsets.symmetric(horizontal: 40),
        child: Material(
          color: Colors.transparent,
          child: Column(
            children: [
              const SizedBox(
                height: 33,
              ),
              const Text(
                '用户需知',
                style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 20),
              Container(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: RichText(
                  text: TextSpan(children: [
                    TextSpan(
                        text:
                            '欢迎您使用${S.of(context).appTitle}APP,请您务必认真阅读'),
                    TextSpan(
                      text: '《用户协议》',
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          RouteNames.push(
                            const WebPage(
                              url: 'assets/html/UserPolicy.html',
                              title: '用户协议',
                            ),
                          );
                        },
                      style: TextStyle(color: ThemeColor.mainColor),
                    ),
                    TextSpan(
                      text: '《隐私政策》',
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          RouteNames.push(
                            const WebPage(
                              url: 'assets/html/PrivacyPolicy.html',
                              title: '隐私政策',
                            ),
                          );
                        },
                      style: TextStyle(color: ThemeColor.mainColor),
                    ),
                    TextSpan(
                      text: '《个人信息收集清单》',
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          RouteNames.push(
                            const WebPage(
                              url: 'assets/html/PersonInfoCollect.html',
                              title: '个人信息收集清单',
                            ),
                          );
                        },
                      style: TextStyle(color: ThemeColor.mainColor),
                    ),
                    TextSpan(
                      text: '《申请使用权限》',
                      recognizer: TapGestureRecognizer()
                        ..onTap = () {
                          RouteNames.push(
                            const WebPage(
                              url: 'assets/html/ApplyUserRight.html',
                              title: '申请使用权限',
                            ),
                          );
                        },
                      style: TextStyle(color: ThemeColor.mainColor),
                    ),
                  ], style: const TextStyle(color: Colors.black)),
                ),
              ),
              const Expanded(child: SizedBox()),
              GestureDetector(
                onTap: () {
                  Navigator.pop(context);
                  if (agreeAction != null) {
                    agreeAction!();
                  }
                },
                child: Container(
                    margin: const EdgeInsets.symmetric(horizontal: 20),
                    padding: const EdgeInsets.symmetric(vertical: 10),
                    decoration: BoxDecoration(
                        color: ThemeColor.mainColor,
                        borderRadius: BorderRadius.circular(20)),
                    alignment: Alignment.center,
                    child: const Text(
                      '同意并登录',
                      style: TextStyle(
                          color: Colors.white, fontWeight: FontWeight.bold),
                    )),
              ),
              const SizedBox(
                height: 10,
              ),
              GestureDetector(
                onTap: () {
                  Navigator.pop(context);
                },
                child: Text(
                  '放弃登录',
                  style: TextStyle(color: ThemeColor.checkNormalColor),
                ),
              ),
              const SizedBox(
                height: 20,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
